import '@/utils/index';
import {isLeftIE9} from "../utils";
import {Message, MessageBox} from 'element-ui';
import {getProjectStatus} from "../api/product/product";

const queryProjectStatus = (callback) => {
	getProjectStatus('WMR').then(res => {
		if (res.code == 200) {
			if (!res.data) {
				MessageBox.alert('项目已被禁用，请联系我们' + process.env.LLT_KF_PHONE + '<p>&#12288;</p>', '警告', {
					confirmButtonText: '确定',
					showClose: false,
					customClass: 'project-status',
					dangerouslyUseHTMLString: true,
					showConfirmButton: false
				});
			} else {
				callback()
			}
		}
	})
};

export default function (to, from, next, store) {
	if (isLeftIE9())
		return;
	sessionStorage.setItem('navCurrent', 'work');
	sessionStorage.setItem('sidebarCurrent', 'workplace');
	sessionStorage.setItem('inProduct', 'no');

	const whiteList = ['/hzBankAdvert', '/jsBankAdvert', '/login', '/loginByTLtoken', '/register', '/help', '/home', '/introduce', '/forgetPassword'];// 不重定向白名单

	function nextPage(user) {
		if (user.passwordNull && to.path !== '/tlagree' && (user.phone == null || user.phone == '')) {
			location.href = _const.HTTPLOCAT + '/authen.html#/tlagree';
		} else {
			next();
		}
	}

	queryProjectStatus(() => {
		if (store.getters.user.user.userId) {
			nextPage(store.getters.user.user);
		} else {
			next();
		}
	});

};


